#! /usr/bin/env node
const fs = require("fs");
const inquirer = require("inquirer");
const path = require("path");
var prompt = inquirer.createPromptModule();
const { program } = require('commander');
program.version('0.0.1')
    .option('-sun_create, --sun_create', 'output extra debugging')
    .option('-cp, --copy <item>', 'output extra debugging')
    .option('-mv, --move <item>', 'output extra debugging')
    .option('-ls, --list <item>', 'output extra debugging');
program.parse(process.argv);
const options = program.opts();
console.log(program.parse(process.argv));
if(options.copy==="sun_cp"){
    fs.copyFileSync(path.join(__dirname+"/src/cp.js"),path.join(__dirname+"/page/cp.js"));
}
if(options.move==="sun_mv"){
    fs.copyFileSync(path.join(__dirname+"/src/mv.js"),path.join(__dirname+"/page/mv.js"));
    fs.unlinkSync(path.join(__dirname+"/src/mv.js"));
}
if(options.list==="sun_ls"){
    console.log(fs.readdirSync(path.join(__dirname)));
}
async function creMyPack() {
    const objs = await prompt([
        {
            type: "input",
            name: "name",
            message: "name"
        },
        {
            type: "input",
            name: "version",
            message: "version"
        },
        {
            type: "input",
            name: "description",
            message: "description"
        },
        {
            type: "input",
            name: "entry",
            message: "entry"
        },
    ])
    if (options.sun_create) {
        fs.mkdirSync("Myweb")
        let jname = process.argv[2].split("_")[1]||"Myweb";
        fs.writeFileSync(path.join(__dirname+`/Myweb/${jname}.json`), JSON.stringify(objs));
    };
}
creMyPack()

